<?php


class ShopAction extends Action{
	
	public function _initialize(){
		Vendor("WxJS.AutoLoad");
		$jssdk = new JSSDK(C("WX_APP_ID"), C("WX_APP_SECRET"));
		$signPackage = $jssdk->GetSignPackage();
		$this->assign('signPackage',$signPackage);
	}
	

	//在线充值
	public function pay() {
		$title = "在线充值";
		$this->assign('title',$title);
		
		Vendor("WxPay.AutoLoad");
		
		$order_no = $_GET['reservation_id'];
		$ob = new OrderModel();
		$info = $ob->where(array('id'=>$order_no))->find();
		
		//①、获取用户openid
		$tools = new JsApiPay();
		$openId = $tools->GetOpenid();
		
		//②、统一下单
		$input = new WxPayUnifiedOrder();
		$input->SetBody("商品收款");
		$input->SetAttach("Att:".$order_no);
		$input->SetOut_trade_no($info['id']);
		$input->SetTotal_fee($info['amount']*100);
		$input->SetTime_start(date("YmdHis"));
		// 		$input->SetTime_expire(date("YmdHis", time() + 200));
		$input->SetGoods_tag("tag:".$order_no);
		$input->SetNotify_url('http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"]
				."/club/Notify/Notify.php");
		$input->SetTrade_type("JSAPI");
		$input->SetOpenid($openId);
		$order = WxPayApi::unifiedOrder($input);
		
		// 		var_dump($order);
		$jsApiParameters = $tools->GetJsApiParameters($order);
		
		$this->assign('info',$info);
		$this->assign('jsApiParameters',$jsApiParameters);
// 		$this->display('Shop:order_payment');
		
// 		$this->display('account/pay');
		return ;
	}
	
}